#!/usr/bin/env bash
# A helper script to play with DDlog command-line interface
set -eu

# find itself
Self=$(readlink -f "$0" 2>/dev/null || {
    # XXX readlink -f is only available in GNU coreutils
    cd $(dirname -- "$0")
    n=$(basename -- "$0")
    if [ -L "$n" ]; then
        L=$(readlink "$n")
        if [ x"$L" != x"${L#/}" ]; then
            echo "$L"; exit
        else
            cd "$(dirname -- "$L")"
            n=$(basename -- "$L")
        fi
    fi
    echo "$(pwd -P)/$n"
})
Here=$(dirname "$Self")

# set up environment
classpathFile=("$Here"/../target/scala-*/classpath)
classpathFile=${classpathFile[0]}
[[ -s "$classpathFile" ]] || {
    echo "ERROR: missing $classpathFile"
    echo 'Run `make` before using test/ddlog!'
    false
} >&2
CLASSPATH=$(cat "$classpathFile")
export CLASSPATH

exec java org.deepdive.ddlog.DeepDiveLog "$@"
